Skip to content

feat(egg-bin): add bundle subcommand#5888

Merged
killagu merged 5 commits intonextfrom
split/17-egg-bin-bundle-cmd
May 1, 2026
Merged

feat(egg-bin): add bundle subcommand#5888
killagu merged 5 commits intonextfrom
split/17-egg-bin-bundle-cmd

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented Apr 21, 2026

Thin wrapper over @eggjs/egg-bundler.bundle() using @oclif/core. Exposes --output/--manifest/--framework/--mode/--no-tegg/--force-external/--inline-external. Re-exports from src/index.ts so tsdown's unused-dep check sees the @eggjs/egg-bundler dependency.

Part of #5863 split. Tracking: #5871.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new bundle command to package Egg applications with configurable output, manifest, framework selection, build mode (production/development), externals handling, and optional tegg-decorated file collection. Displays bundled file count and manifest path.
  • Tests

    • Added unit tests validating default and flag-driven bundle behaviors.
  • Chores

    • Made the bundler package publishable and added runtime dependencies to support the bundle command.

Copilot AI review requested due to automatic review settings April 21, 2026 15:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9a42f64-27e0-49fd-ad82-563f6fcc4faf

📥 Commits

Reviewing files that changed from the base of the PR and between db55b59 and 5db1226.

📒 Files selected for processing (3)
  • tools/egg-bin/src/commands/bundle.ts
  • tools/egg-bin/test/commands/bundle.test.ts
  • tools/egg-bundler/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • tools/egg-bundler/package.json
  • tools/egg-bin/test/commands/bundle.test.ts

📝 Walkthrough

Walkthrough

Adds a new bundle CLI command to tools/egg-bin, exposes ./commands/bundle in package exports, adds @eggjs/egg-bundler as a runtime dependency, makes tools/egg-bundler publishable, and includes tests that mock and assert bundler invocation and options.

Changes

Cohort / File(s) Summary
Package Manifests
tools/egg-bin/package.json, tools/egg-bundler/package.json
Expose ./commands/bundle subpath for src and dist in egg-bin exports/publishConfig; add runtime dependency @eggjs/egg-bundler to egg-bin; remove "private": true from tools/egg-bundler package.json and add @eggjs/utils to dependencies.
Bundle Command Implementation
tools/egg-bin/src/commands/bundle.ts
Add Bundle command with flags (output, manifest, framework, mode, no-tegg, repeatable force-external/inline-external), path resolution for output/manifest, mode validation, dynamic import of @eggjs/egg-bundler, bundler invocation with resolved options, and CLI summary output.
Module Exports
tools/egg-bin/src/index.ts
Re-export Bundle alongside existing commands (Test, Cov, Dev, Manifest).
Tests
tools/egg-bin/test/commands/bundle.test.ts
Add Vitest tests that mock @eggjs/egg-bundler.bundle and assert correct bundle() arguments for default and custom flag combinations (including externals and tegg flag).

Sequence Diagram

sequenceDiagram
    participant User as User/CLI
    participant Bundle as Egg-Bin Bundle Command
    participant Bundler as `@eggjs/egg-bundler`
    participant FS as Filesystem

    User->>Bundle: run `egg-bin bundle` with flags
    Bundle->>Bundle: resolve base/output/manifest paths\nvalidate mode, parse externals, determine framework
    Bundle->>Bundle: debug-log options
    Bundle->>Bundler: dynamic import then call `bundle(options)`
    Bundler->>FS: write bundled files & manifest
    Bundler-->>Bundle: return { outputDir, manifestPath, files }
    Bundle-->>User: print bundle summary (dir, file count, manifest)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jerryliang64
  • fengmk2

Poem

🐇 I hop to pack each egg so neat,
I follow flags and paths with fleet,
A bundler friend makes output sweet,
Files gathered, manifest complete,
📦🥚✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a new bundle subcommand to egg-bin, which is the primary objective of this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/17-egg-bin-bundle-cmd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new bundle command to the egg-bin tool, enabling the packaging of Egg.js applications into deployable artifacts via @eggjs/egg-bundler. The implementation includes a new command class with support for output directories, manifest paths, and build modes. Feedback recommends utilizing getFrameworkPath from @eggjs/utils to ensure consistent and correct framework path resolution across different environments.

Comment thread tools/egg-bin/src/commands/bundle.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new bundle subcommand to egg-bin as a thin oclif wrapper around @eggjs/egg-bundler.bundle() and exposes it via package exports.

Changes:

  • Introduces tools/egg-bin/src/commands/bundle.ts implementing the new bundle command and flags.
  • Re-exports the Bundle command from tools/egg-bin/src/index.ts.
  • Adds @eggjs/egg-bundler dependency and exports for the new command entrypoint in tools/egg-bin/package.json.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tools/egg-bin/src/index.ts Re-exports the new Bundle command from the package entrypoint.
tools/egg-bin/src/commands/bundle.ts Implements the bundle oclif command wrapping @eggjs/egg-bundler.
tools/egg-bin/package.json Adds dependency and export paths for the new bundle command.

Comment thread tools/egg-bin/src/commands/bundle.ts Outdated
Comment thread tools/egg-bin/src/commands/bundle.ts
Comment thread tools/egg-bin/src/commands/bundle.ts Outdated
Comment thread tools/egg-bin/src/commands/bundle.ts
Comment thread tools/egg-bin/src/commands/bundle.ts
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 30, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5db1226
Status: ✅  Deploy successful!
Preview URL: https://11ec5857.egg-v3.pages.dev
Branch Preview URL: https://split-17-egg-bin-bundle-cmd.egg-v3.pages.dev

View logs

@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from 0f2e7ca to ec61bad Compare April 30, 2026 14:53
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 30, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5db1226
Status: ✅  Deploy successful!
Preview URL: https://efb9b14a.egg-cci.pages.dev
Branch Preview URL: https://split-17-egg-bin-bundle-cmd.egg-cci.pages.dev

View logs

@killagu killagu force-pushed the split/16-bundler-tegg-fixture branch from b54fb4c to 77295b4 Compare April 30, 2026 15:16
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from ec61bad to 5fb9bfc Compare April 30, 2026 15:21
@killagu killagu force-pushed the split/16-bundler-tegg-fixture branch from 77295b4 to ccb1b56 Compare April 30, 2026 15:25
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from 5fb9bfc to c987d7c Compare April 30, 2026 15:37
@killagu killagu force-pushed the split/16-bundler-tegg-fixture branch from ccb1b56 to bb07df4 Compare April 30, 2026 16:47
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch 2 times, most recently from d0f4b08 to c987d7c Compare April 30, 2026 16:48
@killagu killagu force-pushed the split/16-bundler-tegg-fixture branch from bb07df4 to ccb1b56 Compare April 30, 2026 16:48
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from c987d7c to e340159 Compare May 1, 2026 05:37
@killagu killagu changed the base branch from split/16-bundler-tegg-fixture to next May 1, 2026 05:38
Copilot AI review requested due to automatic review settings May 1, 2026 13:27
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from e340159 to 005b155 Compare May 1, 2026 13:27
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.03%. Comparing base (c58b369) to head (5db1226).
⚠️ Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
tools/egg-bin/src/commands/bundle.ts 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5888      +/-   ##
==========================================
- Coverage   85.53%   85.03%   -0.51%     
==========================================
  Files         662      665       +3     
  Lines       18888    19100     +212     
  Branches     3664     3716      +52     
==========================================
+ Hits        16156    16241      +85     
- Misses       2359     2466     +107     
- Partials      373      393      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new egg-bin bundle CLI command that wraps @eggjs/egg-bundler.bundle() so apps can be bundled via the standard Egg developer toolchain.

Changes:

  • Introduce a new oclif command bundle with flags for output, manifest, framework, mode, tegg, and external overrides.
  • Export the new command from tools/egg-bin/src/index.ts.
  • Add @eggjs/egg-bundler as a runtime dependency and expose the new command via package exports.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tools/egg-bin/src/index.ts Re-exports the new Bundle command alongside existing commands.
tools/egg-bin/src/commands/bundle.ts New oclif command implementation that parses flags and calls @eggjs/egg-bundler.bundle().
tools/egg-bin/package.json Adds exports for the new command and adds @eggjs/egg-bundler dependency.

Comment thread tools/egg-bin/src/commands/bundle.ts
Copilot AI review requested due to automatic review settings May 1, 2026 13:40
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tools/egg-bin/test/commands/bundle.test.ts (1)

45-77: ⚡ Quick win

Add explicit --framework override coverage.

This case validates most flags, but --framework override behavior is still untested. Adding one focused assertion for that flag would close the new command’s flag matrix.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/egg-bin/test/commands/bundle.test.ts` around lines 45 - 77, Add a test
variation that passes an explicit --framework flag to Bundle.run and assert
bundleMock received the framework path built from getFrameworkPath for that
override; specifically update the existing test invocation of Bundle.run to
include '--framework', 'my-framework' (or add a new it block) and change/extend
the expect(bundleMock).toHaveBeenCalledWith to verify the framework property
equals getFrameworkPath({ framework: 'my-framework', baseDir }) while keeping
other expected options the same; reference Bundle.run, bundleMock, and
getFrameworkPath to locate where to modify the args and assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/egg-bin/test/commands/bundle.test.ts`:
- Around line 45-77: Add a test variation that passes an explicit --framework
flag to Bundle.run and assert bundleMock received the framework path built from
getFrameworkPath for that override; specifically update the existing test
invocation of Bundle.run to include '--framework', 'my-framework' (or add a new
it block) and change/extend the expect(bundleMock).toHaveBeenCalledWith to
verify the framework property equals getFrameworkPath({ framework:
'my-framework', baseDir }) while keeping other expected options the same;
reference Bundle.run, bundleMock, and getFrameworkPath to locate where to modify
the args and assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b834fde-2d7f-4a6f-9e07-389aec9b2a71

📥 Commits

Reviewing files that changed from the base of the PR and between 31450d7 and db55b59.

📒 Files selected for processing (1)
  • tools/egg-bin/test/commands/bundle.test.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread tools/egg-bin/src/commands/bundle.ts Outdated
Comment thread tools/egg-bin/test/commands/bundle.test.ts
Comment thread tools/egg-bundler/package.json
@killagu killagu merged commit 101ab97 into next May 1, 2026
24 of 26 checks passed
@killagu killagu deleted the split/17-egg-bin-bundle-cmd branch May 1, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants